package com.qf.votedemo.phone.controller;

import com.qf.votedemo.phone.service.TokenServer;
import com.qf.votedemo.vo.ResultVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lx
 * @since 2023-02-24
 */
@RestController
@RequestMapping("/phone")
@CrossOrigin
@Slf4j
public class PhoneController {

    @Autowired
    private TokenServer tokenServer;

    /**
     * token颁发接口
     *
     * @param phoneNum
     * @return jwtToken
     */
    @RequestMapping("/createToken")
    public ResultVo createToken(String phoneNum) throws Exception {
        log.debug("接受到的参数为phoneNum={}", phoneNum);
        String newToken = tokenServer.crearToken(phoneNum);
        ResultVo ok = ResultVo.ok();
        ok.put("token", newToken);
        return ok;
    }


    @RequestMapping("/createTokenRedis")
    public ResultVo createTokenRedis(String phoneNum) {
        log.debug("接受到的参数为phoneNum={}", phoneNum);
        String tokenRedis = tokenServer.crearTokenRedis(phoneNum);
        ResultVo ok = ResultVo.ok();
        ok.put("token",tokenRedis);
        return ok;
    }


}
